package com.cal.utms.entity;

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import java.util.List;

/**
 * The persistent class for the permissions database table.
 * 
 */
@Entity
@Table(name = "permissions")
@NamedQuery(name = "Permission.findAll", query = "SELECT p FROM Permission p")
public class Permission implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	private String name;
	@Column(name = "`CREATE`")
	private boolean create;
	private boolean confirm;
	private boolean reject;
	private boolean view;

	@LazyCollection(LazyCollectionOption.FALSE)
	@OneToMany(mappedBy = "permission")
	private List<Screen> screens;

	public Permission() {
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public boolean getConfirm() {
		return this.confirm;
	}

	public void setConfirm(boolean confirm) {
		this.confirm = confirm;
	}

	public boolean getCreate() {
		return this.create;
	}

	public void setCreate(boolean create) {
		this.create = create;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean getReject() {
		return this.reject;
	}

	public void setReject(boolean reject) {
		this.reject = reject;
	}

	public boolean getView() {
		return this.view;
	}

	public void setView(boolean view) {
		this.view = view;
	}

	public List<Screen> getScreens() {
		return this.screens;
	}

	public void setScreens(List<Screen> screens) {
		this.screens = screens;
	}

	public Screen addScreen(Screen screen) {
		getScreens().add(screen);
		screen.setPermission(this);

		return screen;
	}

	public Screen removeScreen(Screen screen) {
		getScreens().remove(screen);
		screen.setPermission(null);

		return screen;
	}

}